﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Frame.Lib.Core.Cache;

namespace Forum.Web.BaseCode
{
    public class Paras
    {
        public static int TopicPageSize
        {
            get
            {
                string pageSize = CacheManager.Instance.ParasContainer["TopicPageSize"];
                if (string.IsNullOrEmpty(pageSize))
                {
                    return 30;
                }
                else
                {
                    try
                    {
                        return int.Parse(pageSize);
                    }
                    catch
                    {
                        return 30;
                    }
                }
            }
        }

        public static int PostPageSize
        {
            get
            {
                string pageSize = CacheManager.Instance.ParasContainer["PostPageSize"];
                if (string.IsNullOrEmpty(pageSize))
                {
                    return 15;
                }
                else
                {
                    try
                    {
                        return int.Parse(pageSize);
                    }
                    catch
                    {
                        return 15;
                    }
                }
            }
        }

        /// <summary>
        /// 上传的附件存储方式 1：按天  2：按月
        /// </summary>
        public static string AttachSaveMode
        {
            get
            {
                string uploadSaveMode = CacheManager.Instance.ParasContainer["UploadSaveMode"];
                if (string.IsNullOrEmpty(uploadSaveMode))
                {
                    return "1";
                }
                else
                {
                    return uploadSaveMode;
                }
            }
        }


        /// <summary>
        /// 附件目录
        /// </summary>
        public static string AttachDir
        {
            get
            {
                string attachDir = CacheManager.Instance.ParasContainer["AttachDir"];
                if (string.IsNullOrEmpty(attachDir))
                {
                    return "upload";
                }
                else
                {
                    return attachDir;
                }
            }
        }

        public static string AttachExt
        {
            get
            {
                string attachExt = CacheManager.Instance.ParasContainer["AttachExt"];
                if (string.IsNullOrEmpty(attachExt))
                {
                    return "txt,rar,zip,jpg,jpeg,gif,png,swf,wmv,avi,wma,mp3,mid,pdf";
                }
                else
                {
                    return attachExt;
                }
            }
        }

        /// <summary>
        /// 附件的最大限制。
        /// </summary>
        public static int AttachMaxSize
        {
            get
            {               
                string attachMaxSize = CacheManager.Instance.ParasContainer["AttachMaxSize"];
                if (string.IsNullOrEmpty(attachMaxSize))
                {
                    return 1024 * 1024 * 2;
                }
                else
                {
                    try
                    {
                        return int.Parse(attachMaxSize);
                    }
                    catch
                    {
                        return 1024 * 1024 * 2;
                    }
                }
            }
        }

    }
}